<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.css" rel="stylesheet" />
		<link href="../css/iconfont.css" rel="stylesheet" />
		<link href="../css/iconfont2.css" rel="stylesheet" />
		<script src="../js/mui.js"></script>
		<script src="../js/jquery.min.js"></script>
		<script src="../js/req.js"></script>
		<style>
			#cd {
				padding: 10px;
			}

			p {
				color: black;
				font-size: 15px;
				margin-top: 10px;
			}

			#p {
				line-height: 28px;
			}

			a {
				color: black;
			}

			span {
				margin-top: 10px;
			}

			.btn {
				height: 28px;
				line-height: 14px;
				float: right;
				margin: 0 10px 0 0;
			}

			#bt {
				position: fixed;
				top: 80%;
				left: 5%;
				width: 90%;
				height: 45px;
				border-radius: 20px;
				line-height: 10px;
				font-size: 18px;
			}

			#col {
				color: orange;
			}
		</style>
	</head>

	<body>


		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">房屋申请</h1>
		</header>

		<div class="mui-content" id="showList">
			
			<div class="mui-segmented-control">
				<a class="mui-control-item mui-active" href="#item1">待认证</a>
				<a class="mui-control-item" href="#item2">认证通过</a>
			</div>
			
			<div id="item1" class="mui-control-content  mui-active">
				
			</div>


			<div id="item2" class="mui-control-content">
				
			</div>

		</div>

	</body>

	<script>
		mui.ready(function() {
			getList();
		})

		function getList() {
			mui.ajax(apiurl + 'api/getCmtyRoomRecord', {
				dataType: 'json', //服务器返回json格式数据
				type: 'get', //HTTP请求类型
				timeout: 10000, //超时时间设置为10秒；
				headers: {
					"Authorization": localStorage.getItem("mtoken"),
					// "Authorization": 'c5d6d0f14a3d591ecacfahdabaebfbddabe41ad',
				},
				success: function(data) {
					console.log(data)
					var html1 = "";
					var html2 = "";
					mui.each(data.data, function(index, ele) {
						
						if(ele.certState=='wait_cert'){
							html1 += `
										<div class="mui-card" style="padding: 10px;" data-id='${ ele.id}'>
											<h4>${ ele.community+ele.building+ele.unit+ele.room}</h4>
											<span id="p"><b>姓名：</b>${ ele.name}</span>
											<br />
											<span id="p"><b>身份：</b>${ ele.userType}</span>
											<br />
											<span id="p"><b>申请时间：</b>${ ele.createTime}</span>
											<br /><br />
											<button type="button" class="btn mui-btn mui-btn-blue success">通过</button>
											<button type="button" class="btn mui-btn mui-btn-red fail">不通过</button>
										</div>
										`;
						}
						
						else{
							html2 += `
										<div class="mui-card" style="padding: 10px;" data-id='${ ele.id}'>
											<h4>${ ele.community+ele.building+ele.unit+ele.room}</h4>
											<span id="p"><b>姓名：</b>${ ele.name}</span>
											<br />
											<span id="p"><b>身份：</b>${ ele.userType}</span>
											<br />
											<span id="p"><b>申请时间：</b>${ ele.createTime}</span>
											<br /><br />
											<span id="p"><b>认证时间：</b>${ ele.certTime}</span>
											<br /><br />
										</div>
										`;
						}
					})

					$("#item1").html(html1);
					$("#item2").html(html2);

					mui('.mui-card').on('tap', '.success', function() {
						//绑定通过方法
						var id = $(this).parent().data('id');
						//修改
						console.log(id)
						//调用接口通过审核
						updateRecord(id, '1');
					})

					mui('.mui-card').on('tap', '.fail', function() {
						//绑定通过方法
						var id = $(this).parent().data('id');
						//修改
						console.log(id)
						//调用接口通过审核
						updateRecord(id, '2');
					})

				},
				error: function(xhr, type, errorThrown) {

				}
			});

		}

		function updateRecord(id, state) {

			mui.ajax(apiurl + 'api/certedRoom?certRes=' + state + '&remarks=无&roomRecordId=' + id, {
				dataType: 'json', //服务器返回json格式数据
				type: 'get', //HTTP请求类型
				timeout: 10000, //超时时间设置为10秒；
				headers: {
					"Authorization": localStorage.getItem("mtoken"),
					// "Authorization": 'c5d6d0f14a3d591ecacfahdabaebfbddabe41ad',
				},
				success: function(data) {
					console.log(data);
					// 刷新数据
					getList();
				},
				error: function(xhr, type, errorThrown) {

				}
			});
		}
	</script>
</html>